<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>群发信息</title>
  <script src="/webjars/stomp-websocket/stomp.min.js"></script>
</head>
<body>
<label><input type="text" id="msg"/></label>
<button onclick="sendMsg()">发送</button>
<script>

        // 设置 WebSocket 的连接地址 ws://localhost:7170/websocket
        let socket = new WebSocket('ws://localhost:7170/websocket')
        let stompClient = Stomp.over(socket);

        function sendMsg() {
            const msg = document.getElementById('msg').value
            // 发送输入框内的信息, /sendMsg 即为 @MessageMapping 中配置的地址
            stompClient.send("/sendMsg", {}, msg)
            alert('发送成功')
        }

    </script>
</body>
</html>